<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title>子角色管理</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1>子角色管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="${ctx }/sysRole/zxRoleList.html">角色管理</a></li>
            <li class="active"><a href="#">子角色管理</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                    <div class="form-group form-group-xs">
                        <label for="name">子角色名称:</label>
                        <input class="form-control" type="text" id="name" placeholder="子角色名称" maxlength="50" />
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查&nbsp;询</button>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             <a href="zxSubRoleEdit.html?opType=0&pid=${role.id}" class="btn btn-default btn-sm">新&nbsp;增</a>
             <label class="btn btn-default btn-sm" onclick="batchChangeStatus(1)">启&nbsp;用</label>
             <label class="btn btn-default btn-sm" onclick="batchChangeStatus(0)">停&nbsp;用</label>
             <a href="${ctx }/sysRole/zxRoleList.html" class="btn btn-danger btn-sm">返&nbsp;回</a>
        </div>
  
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
    	function changeStatus(id, status) {
    		$.post("changeStatus.html", {
    			id : id,
    			status : status
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.HN.message.alert("操作成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json").error(function(err) {
    			top.window.document.location = "${ctx}/login.html"; 
    		}); 
    	}
    	
    	function batchChangeStatus(status) {
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "消息", "error");
    			return;
    		}
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			list.push({"id":rowId, "status":status});
    		}
    		$.post("batchChangeStatus.html", {
    			"array" : json.jsonToString(list)
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.HN.message.alert("操作成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json").error(function(err) {
    			top.window.document.location = "${ctx}/login.html"; 
    		}); 
    	}
    	
    	function search(page) {
    		var name = $.trim($("#name").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"name":name},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "getZxSubRoleList.html",
                mtype: "post",
                postData:{"main":0, "pid":"${role.id}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                    '操作',
					'子角色名称', 
					'状态', 
					'备注' 
					
                ],
                colModel: [
                    { name: 'operate', width: 10, align:"center", sortable: false,
	                   formatter : function(val, opts, rowdata) {
    	                  var str =  "<a href='zxSubRoleEdit.html?opType=1&id=" + rowdata.id + "&pid=${role.id}' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='编辑'></a>";
		                       	
					        str += "<a href='javascript:changeStatus(\""+rowdata.id+"\", 0);'>权限管理</a>"
				               
	    	               return str;
	                }},
                    { name: 'name', width: 10, align:"center", sortable: false},
                    { name: 'statusName', width: 5, align: 'center', sortable: false},
                    { name: 'remark', width: 15, align:"left", sortable: false}
                    
                ],
                rowNum: 10,
                rowList: [10, 20, 30],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${role.name}",
                jsonReader: {
                    id: "id"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
    </script>
</body>
</html>












